# Import libraries 
import cv2 
import numpy as np 
import matplotlib.pyplot as plt 
  
image = cv2.imread('count.jpg') 
image=cv2.resize(image,(818,1091)) #因为图片太大，所以改变了图片的大小
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 
  
blur = cv2.GaussianBlur(gray, (11, 11), 0) 
canny = cv2.Canny(blur, 30, 150, 3) 
dilated = cv2.dilate(canny, (1, 1), iterations=0) 
  
(cnt, hierarchy) = cv2.findContours( 
    dilated.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) 
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) 
cv2.drawContours(rgb, cnt, -1, (0, 0, 255), 1)  

print("coins in the image : ", len(cnt)) 
str='the number : '+str(len(cnt))  #想在图片上显示鸡蛋个数信息，这是需要显示的字符串
img=cv2.putText(rgb,str,(0,20),cv2.FONT_HERSHEY_TRIPLEX,0.6,(0,0,255),1)  #将文字显示到图片上

cv2.imshow('I',rgb)  #展示图片
cv2.waitKey(0)